<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "zs_ad_img".
 *
 * @property integer $id
 * @property string $img_path
 * @property integer $type
 * @property integer $create_time
 * @property integer $update_time
 */
class AdImg extends \yii\db\ActiveRecord
{
    public static $_type = [

    ];
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'zs_ad_img';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['type', 'create_time', 'update_time'], 'integer'],
            [['img_path'], 'string', 'max' => 200]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'img_path' => '图片路径',
            'title' => '图片标题',
            'type' => '广告位置；1首页；2提交页；3商家列表；4供求列表；5',
            'create_time' => '创建时间',
            'update_time' => '更新时间',
        ];
    }

    public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time'
                ],
            ]
        ];
    }


    public static function getAd($type = 1)
    {
        if($type == 3){
            $model = AdImg::findAll(['type' => $type]);
        }else{
            $model = AdImg::findOne(['type' => $type]);
        }
        return $model;
    }
}
